package com.buzz.middleware.dynamic.thread.pool.sdk.trigger.listener;

import com.buzz.middleware.dynamic.thread.pool.sdk.domain.IDynamicThreadPoolService;
import com.buzz.middleware.dynamic.thread.pool.sdk.domain.model.ThreadPoolConfigEntity;
import com.buzz.middleware.dynamic.thread.pool.sdk.registry.IRegistry;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.listener.MessageListener;

import java.util.List;

/**
 * @Author: LiBaoxuan
 * @CreateTime: 2025-01-05  15:32
 * @Description: TODO
 */
@Slf4j
@AllArgsConstructor
public class ThreadPoolConfigAdjustListener implements MessageListener<ThreadPoolConfigEntity> {

    private final IDynamicThreadPoolService dynamicThreadPoolService;
    private final IRegistry registry;

    @Override
    public void onMessage(CharSequence channel, ThreadPoolConfigEntity threadPoolConfigEntity) {
        // 更新数据
        dynamicThreadPoolService.updateThreadPoolConfig(threadPoolConfigEntity);
        // 上报数据
        List<ThreadPoolConfigEntity> threadPoolConfigEntityList = dynamicThreadPoolService.queryThreadPoolList();
        registry.reportThreadPool(threadPoolConfigEntityList);
        log.info("");
        ThreadPoolConfigEntity threadPoolConfigEntityCurrent = dynamicThreadPoolService.queryThreadPoolByName(threadPoolConfigEntity.getThreadPoolName());
        registry.reportThreadPoolConfigParameter(threadPoolConfigEntityCurrent);
        log.info("");
    }

}
